﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Business;

namespace University.Workshop.Presenters.OutflowMoney.Search
{
    public class PresenterSearchOutflow
    {
        ISearchOutflowView view;
        public PresenterSearchOutflow(ISearchOutflowView view)
        {
            this.view = view;
        }

        public void SearchOutflow()
        {
            try
            {
                decimal totalMoney = 0;
                view.ExpensesFinded = ManagerExpenseControl.SearchOutFlowByDates(view.InitialDate, view.EndDate,ref totalMoney);
                view.totalMoney = totalMoney;
            }
            catch (Exception ex)
            {
                view.ExpensesFinded = null;
                view.NotifyErrorMessage(ex.Message);
            }
        }

        public void SendToRead(Model.ExpenseControl expenseControl)
        {
            if (expenseControl.IsWaterExpense)
            {
                Model.WaterPurchase expense = ManagerWaterPurchase.GetWaterPurchaseById(expenseControl.DateRegistry);
                view.NavigateToRead(expense);
            }
            else
            {
                Model.Expense expense = ManagerExpense.GetExpenseById(expenseControl.DateRegistry);
                view.NavigateToRead(expense);
            }    
        }
    }
}
